package com.pd.backend.web.controller.net;


import com.pd.backend.common.R;
import com.pd.backend.domain.dto.LoginDto;
import com.pd.backend.ex.CustomerException;
import com.pd.backend.service.net.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录
 */
@RestController
@RequestMapping("/net/login")
@CrossOrigin
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     * @param loginDto
     * @return
     */
    @PostMapping
    public R<String> login(@RequestBody LoginDto loginDto){
        String account = loginDto.getAccount();
        String password = loginDto.getPassword();
        String code = loginDto.getCode();
        // 唯一标识
        String key = loginDto.getKey();

        // 生成令牌
        Map<String,String> map = new HashMap<>();
        // 在service中 将查到的用户信息 存入redis
        String token = loginService.login(account,password,code,key);
        map.put("token",token);
        R<String> result = new R();
        result.setMap(map);
        result.setCode(200);
        result.setMsg("登录成功");
        return result;
    }
}
